package ${basepackage}.${service_project_name}.service.impl;

import ${basepackage}.${base_project_name}.entity.${table.className};
import ${basepackage}.${service_project_name}.domin.${table.className}Bean;
import ${basepackage}.${service_project_name}.mapper.${table.className}BeanMapper;
import ${basepackage}.${service_project_name}.service.${table.className}BeanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import ac.zlf.maven.mybatis.page.Page;
import ac.zlf.maven.mybatis.page.PageParam;


@Service
public class ${table.className}BeanServiceImpl implements ${table.className}BeanService {

    @Autowired
    private ${table.className}BeanMapper ${table.classNameFirstLower}BeanMapper;

    @Override
    public ${table.className}Bean findBeanById(${table.idColumn.simpleJavaType} id) {
        return ${table.classNameFirstLower}BeanMapper.selectBeanById(id);
    }

    @Override
    public ${table.className}Bean findAvailableBeanById(${table.idColumn.simpleJavaType} id) {
        ${table.className}Bean ${table.classNameFirstLower}Bean = null;

        if(id == null){
            return null;
        }
        ${table.classNameFirstLower}Bean = this.findBeanById(id);

        if(${table.classNameFirstLower}Bean == null) {
            return null;
        }

        return ${table.classNameFirstLower}Bean;
    }

    @Override
    public Page<${table.className}Bean> findBeanPage(PageParam pageParam, ${table.className}Bean ${table.classNameFirstLower}Bean) {
        return ${table.classNameFirstLower}BeanMapper.selectBeanPage(pageParam, ${table.classNameFirstLower}Bean);
    }

    @Override
    public List<${table.className}Bean> findBeanAll(${table.className}Bean ${table.classNameFirstLower}Bean) {
        return ${table.classNameFirstLower}BeanMapper.selectBeanAll(${table.classNameFirstLower}Bean);
    }

    @Override
    @Transactional
    public void doAdd(${table.className}Bean ${table.classNameFirstLower}Bean) {
        //保存到数据库
        ${table.classNameFirstLower}BeanMapper.insert(${table.classNameFirstLower}Bean);
    }

    @Override
    @Transactional
    public void doUpdate(${table.className}Bean ${table.classNameFirstLower}Bean) {

        ${table.classNameFirstLower}BeanMapper.updateByPrimaryKey(${table.classNameFirstLower}Bean);
    }

    @Override
    @Transactional
    public void doDel(${table.idColumn.simpleJavaType} id) {
        //TODO 验证删除权限
        ${table.className} ${table.classNameFirstLower} = ${table.classNameFirstLower}BeanMapper.selectByPrimaryKey(id);
        //将状态设置为删除//TODO 请确设置的状态跟数据库状态一直

        //${table.classNameFirstLower}.setStatus(Indicator.STATUS_2.getCode());
        ${table.classNameFirstLower}BeanMapper.updateByPrimaryKey(${table.classNameFirstLower});
    }

    @Override
    @Transactional
    public void doDelete(${table.idColumn.simpleJavaType} id) {
        //TODO 验证删除权限
        ${table.classNameFirstLower}BeanMapper.deleteByPrimaryKey(id);
    }
}